package org.pangu.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.alibaba.dubbo.config.AbstractConfig;
import com.alibaba.dubbo.config.ProviderConfig;
import com.alibaba.dubbo.config.spring.context.config.DubboConfigBeanCustomizer;

@Component
public class TagDubboConfigBeanCustomizer implements DubboConfigBeanCustomizer{

	@Autowired
	private DubboProperties dubboProperties;
	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public void customize(String beanName, AbstractConfig dubboConfig) {
		if (dubboConfig instanceof ProviderConfig) {
            providerConfig((ProviderConfig) dubboConfig);
        }
	}
	
	private void providerConfig(ProviderConfig providerConfig) {
        if (StringUtils.isEmpty(providerConfig.getTag())
                && StringUtils.hasText(dubboProperties.getTag())) {
            providerConfig.setTag(dubboProperties.getTag());
        }
    }
}
